/*
 * @Description: 
 * @Author: Jimmy
 * @Date: 2023-07-23 22:01:39
 * @LastEditTime: 2023-08-06 18:44:41
 * @LastEditors:  
 */
import { DataTypes } from 'sequelize';
import seq from '../db/seq';
import Depart from './depart.model';
import Role from './role.model';
const moment = require('moment');

//创建模型
const User = seq.define('User', {
    username: {
        type: DataTypes.STRING,
        allowNull: false,
        unique: true,
        comment: "用户名 唯一"
    },
    phone: {
        type: DataTypes.STRING,
        allowNull: true,
        unique: true,
        comment: "手机号 唯一"
    },
    nickname: {
        type: DataTypes.STRING,
        allowNull: true,
        comment: "用户昵称"
    },
    avatar: {
        type: DataTypes.STRING,
        allowNull: true,
        comment: "用户头像"
    },
    role_id: {
        type: DataTypes.TINYINT,
        allowNull: true,
        comment: "用户角色"
    },
    password: {
        type: DataTypes.STRING(512),
        allowNull: false,
        unique: false,
        comment: "用户密码"
    },
    depart_id: {
        type: DataTypes.TINYINT,
        allowNull: true,
        comment: "所属部门"
    },
    is_admin: {
        type: DataTypes.BOOLEAN,
        allowNull: false,
        defaultValue: 0,
        comment: '0 不是管理员 1 管理员'
    },
    status: {
        type: DataTypes.BOOLEAN,
        allowNull: false,
        defaultValue: 1,
        comment: '0 禁用 1 启用'
    }
}, {
    tableName: 'user',
    createdAt: "createTime",
    updatedAt: "updateTime",
})

// User.sync({force:true});
User.belongsTo(Depart, { foreignKey: 'depart_id',as:'depart_info' });
User.belongsTo(Role, { foreignKey: 'role_id', as:'role_info'});
export default User;
